package com.boot.phoenix.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.boot.phoenix.entity.Test;
import com.boot.phoenix.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"test"})
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping({"list"})
    public List<Test> list() {
        return testService.seletcs();
    }

    @GetMapping({"page"})
    public IPage<Test> page(@RequestParam(value = "page",defaultValue = "1") Integer page, @RequestParam(value = "size",defaultValue = "10")Integer size) {
        long start = System.currentTimeMillis();
        IPage<Test> ipage = testService.page(page,size);
        System.out.println("分页查询耗时 =" + (System.currentTimeMillis() - start) + "毫秒");
        return ipage;
    }

    @GetMapping({"save"})
    public String save() {
        for (int i = 1000; i < 1000000000; i++) {
            Test test = new Test();
            test.setId(i);
            test.setName("zsz" + i);
            testService.save(test);
        }
        return "success";
    }
}
